---
title: 'Replication File: Partisanship, Information, and the Conditional Effects of Scandal on Voting Decisions'
output:
  html_document:
    df_print: paged
---


```{r setup, include=FALSE}
library(knitr)
library(formatR)
options(width=70)
knitr::opts_chunk$set(width=70, echo = TRUE, tidy=TRUE, tidy.opts=list(width.cutoff=70))
```


We load R packages and functions that will be used in the analysis. 

```{r include=T,message=FALSE, warning=FALSE, message=FALSE}
## packages- If do not have packages installed, first use install.packages()
library(foreign)
library(texreg)
library(estimatr)
library(ggplot2)
library(lme4)
library(lmtest)
library(sandwich)
scale.01 <- function(x){(x-min(x, na.rm =T))/(max(x, na.rm =T)-min(x, na.rm =T))}
```

# Load Data

To run the analyses, you must load the `candlongfin.csv`, as shown below. This is in long format, where every row represents a different candidate profile that a particular respondent evaluated. 


```{r include = T, tidy=T, eval=T}
## Load Data
candlong <-  read.csv("candlongfin.csv", stringsAsFactors = T)
```


\clearpage

# A summary of key variables

The data include `r nrow(candlong)` candidate profiles from `r length(unique(candlong$ResponseId))` subjects. Listwise deletion is used in cases of item non-response.

The main outcome variable is `chosen.p` reflecting if the candidate was chosen.
```{r include = T, tidy=T, eval=T}
## Load Data
kable(table(candlong$chosen.p), col.names = c("Chosen", "Freq"))
```


The main independent variables are `info.p` representing the information environment of low=0, medium=.5, or high=1, and `news.p` indicating the type of negative scandal, neutral, or positive news about the candidate.

```{r include = T, tidy=T, eval=T}
kable(table(candlong$info.p), col.names = c("Information", "Freq"))
kable(table(candlong$news.p), col.names = c("News", "Freq"))
```

Additional outcomes include `moral.ps`, `shares.ps`, and `cares.ps` indicating the extent to which the respondent believed the candidate to have good morals, share their views, and care about people like them.

```{r}
kable(table(candlong$moral.ps), col.names = c("Moral", "Freq"))
kable(table(candlong$shares.ps), col.names = c("Shares Views", "Freq"))
kable(table(candlong$cares.ps), col.names = c("Cares about Me", "Freq"))
```

Generally, variables ending in `.p` represent candidate attributes: `party.p, religion.p, profession.p, race.p, gender.p, age.p, spending.p, abortion.p, immigration.p`. When these variables are prefaced by an `op`, this means it is the attribute of the opponent in the election scenario. 

Additional variables reflect respondent characteristics. In particular, we use the dummy variables for whether a respondent is a Democrat (`dem`) or Republican (`rep`). We also compare candidate and respondent issue positions using respondent attitudes on variables: `spending, immigration` and `abortion`.

\clearpage

# Main Analyses

This section includes analyses to replicate the tables and figures in the main text.

## Table 2

```{r include = T, tidy=T}
## Column 1 (Main Result): Contrasts medium vs. low, high vs. low
i2  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)


## Column 2: Limit analysis to high vs. medium information environments
medhigh <- subset(candlong, info.p > 0)

i2mh  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                 medhigh, se_type = "stata", 
                 clusters = medhigh$ResponseId)
```

```{r include = T, tidy=T}
## Code below produces a regression table
htmlreg(list(i2, i2mh), file = "table2.doc",
        caption.above = T,
        custom.model.names = c("Vote Choice: Reference- Low",  
                               "Vote Choice: Reference- Medium"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))

```


```{r tidy=T, echo=F, results="asis"}
## Code below produces a regression table
htmlreg(list(i2, i2mh), 
        caption.above = T,
        custom.model.names = c("Vote Choice: Reference-Low",  
                               "Vote Choice: Reference-Medium"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment",
        include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```


## Figure 1

```{r include = T, tidy=T, echo=T}
## Function to plot marginal effect of scandal by information
myscanbyinfoplot <-function(i2, mytitle, xlim1 = c(-.4, .3)){
  
  diffs.low <- coef(i2)[2:6]
  low.cis <- confint(i2)[2:6,]
  
  diffs.med <- c()
  ci.l.med <- c()
  ci.u.med <- c()
  for(i in 2:length(levels(candlong$news.p))){
    medint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)0.5", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    med.main <- coef(i2)[scan]
    med.int <- coef(i2)[medint]
    diffs.med[(i-1)] <- med.main + med.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[medint,medint] + 2*vcov(i2)[scan, medint])
    ci.l.med[(i-1)] <- (med.main + med.int) - 1.96*comp.ses
    ci.u.med[(i-1)] <- (med.main + med.int) + 1.96*comp.ses
  }
  med.cis <- cbind(ci.l.med, ci.u.med)
  
  
  diffs.high <- c()
  ci.l.high <- c()
  ci.u.high <- c()
  for(i in 2:length(levels(candlong$news.p))){
    highint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)1", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    high.main <- coef(i2)[scan]
    high.int <- coef(i2)[highint]
    diffs.high[(i-1)] <- high.main + high.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[highint,highint] + 2*vcov(i2)[scan, highint])
    ci.l.high[(i-1)] <- (high.main + high.int) - 1.96*comp.ses
    ci.u.high[(i-1)] <- (high.main + high.int) + 1.96*comp.ses
  }
  high.cis <- cbind(ci.l.high, ci.u.high)
  
  ## re-order levels
  diffs.low <- diffs.low[c(3,2,1,4,5)]
  diffs.med <- diffs.med[c(3,2,1,4,5)]
  diffs.high <- diffs.high[c(3,2,1,4,5)]
  
  low.cis <- low.cis[c(3,2,1,4,5),]
  med.cis <- med.cis[c(3,2,1,4,5),]
  high.cis <- high.cis[c(3,2,1,4,5),]
  
  news2 <- c("Sexual harassment",               
             "Leaking confidential information",
             "Cheating on spouse",
             "No Recent News",
             "Celebrated wedding anniversary",
             "Honored for public service" )   
  
  par(mar= c(4, 10, 4, 1))
  plot(x=c(diffs.low[1:3], 0, diffs.low[4:5],
           diffs.med[1:3], 0, diffs.med[4:5],
           diffs.high[1:3], 0, diffs.high[4:5]), y=1:18, pch = 15, 
       main = mytitle,
       cex.main = .7, 
       ylab="", 
       yaxt = "n", 
       xlim = xlim1,
       xlab = "Marginal Effect and 95% Confidence Intervals", 
       cex.lab = .8, 
       cex.axis = .8,
       cex=1.1)
  abline(h=1:18, col="light gray", lty=2)
  abline(v= 0, col="red")
  abline(h = c(6.5, 12.5))
  
  cis <- rbind(low.cis[1:3,], 0,low.cis[4:5,],
               med.cis[1:3,], 0,med.cis[4:5,],
               high.cis[1:3,], 0, high.cis[4:5,])
  for(i in 1:18){
    lines(cis[i,], c(i,i), lwd=1.8)
  }
  points(x=c(diffs.low[1:3], 0, diffs.low[4:5],
                  diffs.med[1:3], 0, diffs.med[4:5],
                  diffs.high[1:3], 0, diffs.high[4:5]), 
         y=1:18, 
         pch = 15,
         cex=1.1)
  axis(2,1:18, 
       rep(news2, 3), 
       cex.axis=.65, 
       las=1)
  text(-.3,c(5.5, 11.5, 17.5), c("Low Info", "Medium Info", "High Info"), cex=.8)
  
}
```

```{r include = T, tidy=T, echo=T}
png("figure1.png", width = 6, height = 4, units="in", res=300)
myscanbyinfoplot(i2=i2,
                 mytitle = "Average Marginal Effect of News vs. No Recent News on Vote Choice \n By Information Level")
dev.off()
```

![](figure1.png)\


## Figure 2

The code below subsets the data by candidate-respondent partisan combinations.
```{r include = T, tidy=T, echo=T}
repvrepc <- subset(candlong, demrep == 0 &
                     party.p == "Republican")
i2.repvrepc  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                 data=repvrepc, 
                 se_type = "stata", 
                 clusters = repvrepc$ResponseId)

repvdemc <- subset(candlong, demrep == 0 &
                     party.p == "Democrat")
i2.repvdemc  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                          data=repvdemc, 
                          se_type = "stata", 
                          clusters = repvdemc$ResponseId)

demvrepc <- subset(candlong, demrep == 1 &
                     party.p == "Republican")
i2.demvrepc  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                          data=demvrepc, 
                          se_type = "stata", 
                          clusters = demvrepc$ResponseId)

demvdemc <- subset(candlong, demrep == 1 &
                     party.p == "Democrat")
i2.demvdemc  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                          data=demvdemc, 
                          se_type = "stata", 
                          clusters = demvdemc$ResponseId)
```

The code below creates a function for gathering the point estimates and confidence intervals from each model into a data frame.

```{r include = T, tidy=T, echo=T}
retdf <- function(i2, comparison){
  diffs.low <- coef(i2)[2:6]
  low.cis <- confint(i2)[2:6,]
  diffs.med <- c()
  ci.l.med <- c()
  ci.u.med <- c()
  for(i in 2:length(levels(candlong$news.p))){
    medint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)0.5", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    med.main <- coef(i2)[scan]
    med.int <- coef(i2)[medint]
    diffs.med[(i-1)] <- med.main + med.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[medint,medint] + 2*vcov(i2)[scan, medint])
    ci.l.med[(i-1)] <- (med.main + med.int) - 1.96*comp.ses
    ci.u.med[(i-1)] <- (med.main + med.int) + 1.96*comp.ses
  }
  med.cis <- cbind(ci.l.med, ci.u.med)
  diffs.high <- c()
  ci.l.high <- c()
  ci.u.high <- c()
  for(i in 2:length(levels(candlong$news.p))){
    highint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)1", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    high.main <- coef(i2)[scan]
    high.int <- coef(i2)[highint]
    diffs.high[(i-1)] <- high.main + high.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[highint,highint] + 2*vcov(i2)[scan, highint])
    ci.l.high[(i-1)] <- (high.main + high.int) - 1.96*comp.ses
    ci.u.high[(i-1)] <- (high.main + high.int) + 1.96*comp.ses
  }
  high.cis <- cbind(ci.l.high, ci.u.high)
  
  ## re-order levels
  diffs.low <- diffs.low[c(3,2,1,4,5)]
  diffs.med <- diffs.med[c(3,2,1,4,5)]
  diffs.high <- diffs.high[c(3,2,1,4,5)]
  low.cis <- low.cis[c(3,2,1,4,5),]
  med.cis <- med.cis[c(3,2,1,4,5),]
  high.cis <- high.cis[c(3,2,1,4,5),]
  news2 <- c("Sexual harassment",               
             "Leaking confidential information",
             "Cheating on spouse",
             "No Recent News",
             "Celebrated wedding anniversary",
             "Honored for public service" )   
  x <- data.frame(points = c(diffs.low[1:3], 0, diffs.low[4:5],
                           diffs.med[1:3], 0, diffs.med[4:5],
                           diffs.high[1:3], 0, diffs.high[4:5]),
                news = rep(news2, 3),
                cil = c(low.cis[1:3,1], 0,low.cis[4:5,1],
               med.cis[1:3,1], 0,med.cis[4:5,1],
               high.cis[1:3,1], 0, high.cis[4:5,1]),
               ciu = c(low.cis[1:3,2], 0,low.cis[4:5,2],
                       med.cis[1:3,2], 0,med.cis[4:5,2],
                       high.cis[1:3,2], 0, high.cis[4:5,2]),
               info = c(rep("Low", 6),rep("Medium",6),rep("High", 6)),
               group = comparison)
  return(x)
  }
```

The code below combines all four models into one dataframe to make it easier to plot.

```{r include = T, tidy=T, echo=T}
df.demvdemc <-retdf(i2=i2.demvdemc, comparison = "Democratic Respondent \n Democratic Candidate")
df.demvrepc <-retdf(i2=i2.demvrepc, comparison = "Democratic Respondent \n Republican Candidate")
df.repvdemc <-retdf(i2=i2.repvdemc, comparison = "Republican Respondent \n Democratic Candidate")
df.repvrepc <-retdf(i2=i2.repvrepc, comparison = "Republican Respondent \n Republican Candidate")

comball <- rbind(df.demvdemc, df.demvrepc,df.repvdemc,df.repvrepc)
comball$news <- factor(comball$news, levels= c("Sexual harassment",               
                                               "Leaking confidential information",
                                               "Cheating on spouse",
                                               "No Recent News",
                                               "Celebrated wedding anniversary",
                                               "Honored for public service" ) )
comball$info <- factor(comball$info, levels= c("Low", "Medium", "High"))
comball$group <- as.factor(comball$group)
```

The code below plots the results of the four models.


```{r include=T, tidy=T, eval=T, warning=F, message=F}
ggfig2 <- ggplot(data = comball, aes(x=points, y=interaction(news, info), group= info))+
  geom_errorbar(aes(xmax=cil, xmin=ciu), position=position_dodge(.9), width=0)+
  geom_vline(xintercept = 0, color="red") +
  geom_point(stat="identity", position="dodge")+
  theme_bw()+
  facet_grid(~group) +
  geom_hline(yintercept = c(6.5, 12.5))+
  ggtitle("Average Marginal Effect of News vs. No Recent News on Vote Choice \n By Information and Respondent and Candidate Partisanship")+
  xlab("Average Marginal Effect on Probability of Voting for the Candidate")+
  ylab("")+
  xlim(-.45,.3)+
  theme(plot.title = element_text(hjust = 0.5, size=8),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        #panel.border = element_blank(),
        #panel.grid.minor.y = element_blank(),
        legend.text = element_text(size=8),
        axis.text = element_text(size = 8),
        axis.title = element_text(size=8),
        strip.background = element_rect(
          fill="white", size=1, linetype="solid"))+
  scale_y_discrete(labels= rep(c("Sexual harassment",               
                                 "Leaking confidential information",
                                 "Cheating on spouse",
                                 "No Recent News",
                                 "Celebrated wedding anniversary",
                                 "Honored for public service" ) ,3))+
  annotate("text", x=-.3, y=5.6, label="Low Info", size=2.8)+  
  annotate("text", x=-.3, y=11.6, label="Medium Info", size=2.8)+
  annotate("text", x=-.3, y=17.6, label="High Info", size=2.8)
ggsave("figure2facet.png", device = "png",width=9, height=4)
```


![](figure2facet.png)\


\clearpage

## Figure 3

The code below repeats the main analysis for the morality outcome. It relies on a function created above.
```{r include = T, tidy=T, echo=T}

m2  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)

png("figure3.png", width = 6, height = 4, units="in", res=300)
myscanbyinfoplot(i2=m2,
                 mytitle = "Average Marginal Effect of News vs. No Recent News on Candidate Morality \n By Information Level")
dev.off()

```

![](figure3.png)\


\clearpage

## Figure 4

This function generates clustered (by respondent) bootstrap estimates of the differences in the effects of scandal (vs. no recent news) across outcomes.
```{r tidy=T, eval=FALSE}
mydboot <- function(df){
  clusters <- unique(df$ResponseId) # unique clusters
  index <- sample(clusters,length(clusters),replace=TRUE) # resample clusters
  row.nums <- NULL # empty vector
  for (j in 1:length(index)){
    row.nums <- c(row.nums, which(df$ResponseId==index[j])) # identify row numbers for each cluster
  }
  bootdat <- df[row.nums,] # create new data based on row numbers of clusters
  bm2  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                    bootdat, se_type = "stata", 
                    clusters =  bootdat$ResponseId)
  bs2  <- lm_robust(shares.ps ~ news.p*factor(info.p),
                    bootdat, se_type = "stata", 
                    clusters =  bootdat$ResponseId)
  bm2.p <- predict(bm2, newdata = expand.grid(news.p = levels(candlong$news.p),
                                              info.p = c(0, .5, 1)), interval = "confidence")
  bs2.p <- predict(bs2, newdata = expand.grid(news.p = levels(candlong$news.p),
                                              info.p = c(0, .5, 1)), interval = "confidence")
  lab1 <- expand.grid(news.p = levels(candlong$news.p),
                      info.p = c(0, .5, 1))[,1]
  rownames(bm2.p$fit) <- lab1
  rownames(bs2.p$fit) <- lab1
  
  ## Avg. Morality rating vs. Avg. Shares my views rating
  dcheat <- bm2.p$fit[grepl("Recently accused of cheating on spouse", rownames(bm2.p$fit)), 1] -
    bs2.p$fit[grepl("Recently accused of cheating on spouse", rownames(bs2.p$fit)), 1]
  dcon <- bm2.p$fit[grepl("confidential", rownames(bm2.p$fit)), 1] -
    bs2.p$fit[grepl("confidential", rownames(bs2.p$fit)), 1]
  dhar <- bm2.p$fit[grepl("harassment", rownames(bm2.p$fit)), 1] -
    bs2.p$fit[grepl("harassment", rownames(bs2.p$fit)), 1]
  dcheat.low <- dcheat[1]
  dcheat.med <- dcheat[2]
  dcheat.high <- dcheat[3]
  dcon.low <- dcon[1]
  dcon.med <- dcon[2]
  dcon.high <- dcon[3]
  dhar.low <- dhar[1]
  dhar.med <- dhar[2]
  dhar.high <- dhar[3]
  
  ## Avg. Diff in Morality rating from No News vs. Avg. Diff in Shares my views rating from No News
  dcheatm <- bm2.p$fit[grepl("Recently accused of cheating on spouse", rownames(bm2.p$fit)), 1] -
    bm2.p$fit[grepl("No recent", rownames(bm2.p$fit)), 1] 
  dconm <- bm2.p$fit[grepl("confidential", rownames(bm2.p$fit)), 1] -
    bm2.p$fit[grepl("No recent", rownames(bm2.p$fit)), 1]
  dharm <-bm2.p$fit[grepl("harassment", rownames(bm2.p$fit)), 1] -
    bm2.p$fit[grepl("No recent", rownames(bm2.p$fit)), 1]
  
  dcheats <-bs2.p$fit[grepl("Recently accused of cheating on spouse", rownames(bs2.p$fit)), 1] -
    bs2.p$fit[grepl("No recent", rownames(bs2.p$fit)), 1] 
  dcons <- bs2.p$fit[grepl("confidential", rownames(bs2.p$fit)), 1] -
    bs2.p$fit[grepl("No recent", rownames(bs2.p$fit)), 1]
  dhars <-bs2.p$fit[grepl("harassment", rownames(bs2.p$fit)), 1] -
    bs2.p$fit[grepl("No recent", rownames(bs2.p$fit)), 1]
  
  dcheatmsl <- dcheatm[1] - dcheats[1]
  dcheatmsm <- dcheatm[2] - dcheats[2]
  dcheatmsh <- dcheatm[3] - dcheats[3]
  
  dconmsl <- dconm[1] - dcons[1]
  dconmsm <- dconm[2] - dcons[2]
  dconmsh <- dconm[3] - dcons[3]
  
  dharmsl <- dharm[1] - dhars[1]
  dharmsm <- dharm[2] - dhars[2]
  dharmsh <- dharm[3] - dhars[3]
  
  return(cbind(dcheat.low, dcheat.med, dcheat.high,
               dcon.low, dcon.med, dcon.high,
               dhar.low, dhar.med, dhar.high,
               dcheatmsl, dcheatmsm, dcheatmsh,
               dconmsl, dconmsm, dconmsh,
               dharmsl,dharmsm, dharmsh ))}
```

Running this code chunk will generate 1000 estimates. This takes time to evaluate. To compile from the raw code, change `eval=FALSE` to `eval=TRUE` in the markdown file.
```{r tidy=T, eval=FALSE}
set.seed(1234)
myestimates <- do.call("rbind", replicate(1000, mydboot(candlong), simplify = F))
```

The code below generates the point estimates of the differences.
```{r tidy=T}
## Avg. Diff in Morality rating from No News vs. Avg. Diff in Shares my views rating from No News
m2  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)

m2.p <- predict(m2, newdata = expand.grid(news.p = levels(candlong$news.p),
                                          info.p = c(0, .5, 1)), interval = "confidence")

lab1 <- expand.grid(news.p = levels(candlong$news.p),
                    info.p = c(0, .5, 1))[,1]
rownames(m2.p$fit) <- lab1
s2  <- lm_robust(shares.ps ~ news.p*factor(info.p),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)
s2.p <- predict(s2, newdata = expand.grid(news.p = levels(candlong$news.p),
                                          info.p = c(0, .5, 1)), interval = "confidence")
rownames(s2.p$fit) <- lab1
cheatm <- m2.p$fit[grepl("Recently accused of cheating on spouse", rownames(m2.p$fit)), 1] -
  m2.p$fit[grepl("No recent", rownames(m2.p$fit)), 1] 
conm <- m2.p$fit[grepl("confidential", rownames(m2.p$fit)), 1] -
  m2.p$fit[grepl("No recent", rownames(m2.p$fit)), 1]
harm <-m2.p$fit[grepl("harassment", rownames(m2.p$fit)), 1] -
  m2.p$fit[grepl("No recent", rownames(m2.p$fit)), 1]

cheats <-s2.p$fit[grepl("Recently accused of cheating on spouse", rownames(s2.p$fit)), 1] -
  s2.p$fit[grepl("No recent", rownames(s2.p$fit)), 1] 
cons <- s2.p$fit[grepl("confidential", rownames(s2.p$fit)), 1] -
  s2.p$fit[grepl("No recent", rownames(s2.p$fit)), 1]
hars <-s2.p$fit[grepl("harassment", rownames(s2.p$fit)), 1] -
  s2.p$fit[grepl("No recent", rownames(s2.p$fit)), 1]

cheatmsl <- cheatm[1] - cheats[1]
cheatmsm <- cheatm[2] - cheats[2]
cheatmsh <- cheatm[3] - cheats[3]

conmsl <- conm[1] - cons[1]
conmsm <- conm[2] - cons[2]
conmsh <- conm[3] - cons[3]

harmsl <- harm[1] - hars[1]
harmsm <- harm[2] - hars[2]
harmsh <- harm[3] - hars[3]
```

The code below plots the results. To compile from the raw code, change `eval=F` to `eval=T`.
```{r tidy=T, eval=F, cache=F}

## Plot

png("figure4.png", width = 7, height = 4, units="in", res=300)
par(mfrow = c(1,1), oma=c(1,1,1,1),
    mar = c(4, 8, 4, 2))
plot(c(cheatmsl, cheatmsm, cheatmsh,
       conmsl, conmsm, conmsh,
       harmsl,harmsm, harmsh ), 1:9,
     xlim = c(-.2, .1), pch = c(15, 16, 17),
     xlab = "(Avg. Morality Rating in Scandal condition - 'No Recent News') - \n (Avg. Shares my Views Rating in Scandal condition - 'No Recent News')",
     main = "Effect of Scandal on Morality - Effect of Scandal on Shares my Views \n By Type of Scandal and Information Environment",
     cex.main = .8, cex.lab = .8, 
     yaxt="n", cex.axis = .8, ylab = "")
abline(v=0, col = "red")
abline(h = c(3.5, 6.5))
axis(2, c(2, 5, 8), c("Cheating on Spouse", "Confidential Information",
                      "Sexual Harassment"), cex.axis = .7, las =1)
lines( quantile(myestimates[,10], c(0.025,.975)), c(1,1))
lines( quantile(myestimates[,11], c(0.025,.975)), c(2,2))
lines( quantile(myestimates[,12], c(0.025,.975)), c(3,3))
lines( quantile(myestimates[,13], c(0.025,.975)), c(4,4))
lines( quantile(myestimates[,14], c(0.025,.975)), c(5,5))
lines( quantile(myestimates[,15], c(0.025,.975)), c(6,6))
lines( quantile(myestimates[,16], c(0.025,.975)), c(7,7))
lines( quantile(myestimates[,17], c(0.025,.975)), c(8,8))
lines( quantile(myestimates[,18], c(0.025,.975)), c(9,9))
legend("bottomright", pch = rev(c(15, 16, 17)), 
       rev(c("Low Info", "Medium Info", "High Info")),
       cex=.7,  bty="o", bg="white")
dev.off()
```

![](figure4.png)\

\clearpage

# Analyses in the Online Appendix


## Descriptive Statistics

```{r tidy=T}
kable(table(candlong$news.p), col.names = c("News", "Freq"))
kable(table(candlong$info.p), col.names = c("Information", "Freq"))
kable(table(candlong$party.p), col.names = c("Party", "Freq"))
kable(table(candlong$gender.p), col.names = c("Gender", "Freq"))
kable(table(candlong$race.p), col.names = c("Race", "Freq"))
kable(table(candlong$religion.p), col.names = c("Religion", "Freq"))
kable(table(candlong$profession.p), col.names = c("Profession", "Freq"))
kable(table(candlong$age.p), col.names = c("Age", "Freq"))
kable(table(candlong$abortion.p), col.names = c("Abortion", "Freq"))
kable(table(candlong$spending.p), col.names = c("Spending", "Freq"))
kable(table(candlong$immigration.p), col.names = c("Immigration", "Freq"))
```


## Table A3 Logistic Regression

```{r tidy=TRUE, warning=FALSE, message=FALSE}
i2log  <- glmer(chosen.p ~ news.p*factor(info.p) + (1 | ResponseId),
                data=candlong, family = binomial(link="logit"))
i2logmh  <- glmer(chosen.p ~ news.p*factor(info.p) + (1 | ResponseId),
                data=medhigh, family = binomial(link="logit"))
```



```{r tidy=TRUE}
htmlreg(list(i2log, i2logmh), file = "appfigs/table2log.doc",
        caption.above = T,
        custom.model.names = c("Vote Choice: Low, Medium, High", "Vote Choice: Medium, High"),
        
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Logistic Regression on Interaction between News and Information Environment, Random Effects for Respondents",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```

```{r tidy=TRUE, echo=FALSE, results="asis"}
htmlreg(list(i2log, i2logmh),
        caption.above = T,
        custom.model.names = c("Vote Choice", "Vote Choice:Med and High Only"),
        
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Logistic Regression on Interaction between News and Information Environment, Random Effects for Respondents",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```





## Figure A1

This code evaluates the main results using only the first profiles respondents evaluated.
```{r tidy=T}
candlongfirst <- subset(candlong, time < 3)
i2first  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                      candlongfirst, se_type = "stata", 
                      clusters = candlongfirst$ResponseId)
png("appfigs/figurea1.png", width = 6, height = 4, units="in", res=300)
myscanbyinfoplot(i2=i2first,
                 mytitle = "Average Marginal Effect of News vs. No Recent News on Vote Choice \n By Information Level (First Task Only)")
dev.off()
```

![](appfigs/figurea1.png)\




## Figure A2


This analysis removing counterstereotypical levels from the evaluation of results.
```{r tidy=TRUE}
candlongnocs <- subset(candlong,
                       (party.p == "Democrat" & 
                          immigration.p != "Opposes a pathway to citizenship for undocumented immigrants" &
                          opimmigration.p != "Supports a pathway for citizenship for undocumented immigrants" &
                          abortion.p != "Abortion should never be permitted" &
                          opabortion.p != "A woman should always be able to obtain an abortion" &
                          spending.p != "Decrease spending a large amount" &
                          opspending.p != "Increase spending a large amount") | 
                         (party.p == "Republican" & 
                            opimmigration.p != "Opposes a pathway to citizenship for undocumented immigrants" &
                            immigration.p != "Supports a pathway for citizenship for undocumented immigrants" &
                            opabortion.p != "Abortion should never be permitted" &
                            abortion.p != "A woman should always be able to obtain an abortion" &
                            opspending.p != "Decrease spending a large amount" &
                            spending.p != "Increase spending a large amount"))

kable(table(candlongnocs$info.p), col.names = c("Information", "Freq"))
kable(table(candlongnocs$info.p, candlongnocs$news.p))
```

```{r tidy=TRUE}
candlongnocs1 <- subset(candlongnocs, info.p < 1)

i2n  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                  candlongnocs1, se_type = "stata", 
                  clusters = candlongnocs1$ResponseId)


candlongnocs2 <- subset(candlongnocs, info.p == 1)

i2h  <- lm_robust(chosen.p ~ news.p,
                  candlongnocs2, se_type = "stata", 
                  clusters = candlongnocs2$ResponseId)
```

This function plots the two information environments.
```{r tidy=TRUE}
myscanbyinfoplotlowmed <-function(i2, mytitle){
  
  
  diffs.low <- coef(i2)[2:6]
  low.cis <- confint(i2)[2:6,]
  
  diffs.med <- c()
  ci.l.med <- c()
  ci.u.med <- c()
  for(i in 2:length(levels(candlong$news.p))){
    medint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)0.5", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    med.main <- coef(i2)[scan]
    med.int <- coef(i2)[medint]
    diffs.med[(i-1)] <- med.main + med.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[medint,medint] + 2*vcov(i2)[scan, medint])
    ci.l.med[(i-1)] <- (med.main + med.int) - 1.96*comp.ses
    ci.u.med[(i-1)] <- (med.main + med.int) + 1.96*comp.ses
  }
  med.cis <- cbind(ci.l.med, ci.u.med)
  
  ## re-order levels
  diffs.low <- diffs.low[c(3,2,1,4,5)]
  diffs.med <- diffs.med[c(3,2,1,4,5)]
  
  low.cis <- low.cis[c(3,2,1,4,5),]
  med.cis <- med.cis[c(3,2,1,4,5),]
  
  news2 <- c("Sexual harassment",               
             "Leaking confidential information",
             "Cheating on spouse",
             "No Recent News",
             "Celebrated wedding anniversary",
             "Honored for public service" )   
  
  par(mar= c(4, 10, 4, 1))
  plot(x=c(diffs.low[1:3], 0, diffs.low[4:5],
           diffs.med[1:3], 0, diffs.med[4:5]), y=1:12, pch = 15, 
       main = mytitle,
       cex.main = .7, 
       ylab="", 
       yaxt = "n", 
       xlim = c(-.4, .3),
       xlab = "Marginal Effect and 95% Confidence Intervals", 
       cex.lab = .8, 
       cex.axis = .8,
       cex=1.1)
  abline(h=1:12, col="light gray", lty=2)
  abline(v= 0, col="red")
  abline(h = c(6.5))
  
  cis <- rbind(low.cis[1:3,], 0,low.cis[4:5,],
               med.cis[1:3,], 0,med.cis[4:5,])
  for(i in 1:12){
    lines(cis[i,], c(i,i), lwd=1.8)
  }
  points(x=c(diffs.low[1:3], 0, diffs.low[4:5],
             diffs.med[1:3], 0, diffs.med[4:5]), 
         y=1:12, 
         pch = 15,
         cex=1.1)
  axis(2,1:12, 
       rep(news2, 2), 
       cex.axis=.65, 
       las=1)
  text(-.3,c(5.5, 11.5), c("Low Info", "Medium Info"), cex=.8)
  
}
```

This code generates the figure for just the medium and high information environments.
```{r tidy=T}
png("appfigs/nocs.png", width = 6, height = 4, units="in", res=300)
myscanbyinfoplotlowmed(i2n, "Effect of Scandal by Information: No Counterstereotypical Candidates")
dev.off()
```

![](appfigs/nocs.png)\


This analysis evaluates elections where only one candidate has a scandal.

```{r tidy=T}
nonscandal <- levels(candlong$opnews.p)[c(1, 5, 6)]
scandals <- levels(candlong$opnews.p)[c(2, 3, 4)]


candcont <- subset(candlong, (news.p %in% scandals &
                                opnews.p %in% nonscandal) |
                     (news.p %in% nonscandal &
                        opnews.p %in% scandals))

i2ct  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                   candcont, se_type = "stata", 
                   clusters = candcont$ResponseId)

png("appfigs/figureonescandal.png", width = 6, height = 4, units="in", res=300)
myscanbyinfoplot(i2=i2ct, xlim1 = c(-.6, .3),
                 mytitle = "Average Marginal Effect of News vs. No Recent News on Vote Choice \n By Information Level (One Candidate with Scandal)")
dev.off()


```


![](appfigs/figureonescandal.png)\





\clearpage


## Figure A3 Copartisanship

```{r tidy = T}

copartisans <- subset(candlong, (party.p == "Democrat" & candlong$dem == 1) |
                        (party.p == "Republican" & candlong$rep == 1))
oppartisans <- subset(candlong, (party.p == "Democrat" & candlong$rep == 1) |
                        (party.p == "Republican" & candlong$dem == 1))

i2.copartisans  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                          data=copartisans, 
                          se_type = "stata", 
                          clusters = copartisans$ResponseId)
i2.oppartisans  <- lm_robust(chosen.p ~ news.p*factor(info.p),
                             data=oppartisans, 
                             se_type = "stata", 
                             clusters = oppartisans$ResponseId)

df.copartisans <-retdf(i2=i2.copartisans, comparison = "Partisan Respondent \n Co-Partisan Candidate")
df.oppartisans <-retdf(i2=i2.oppartisans, comparison = "Partisan Respondent \n Out-Party Candidate")

comball2 <- rbind(df.copartisans, df.oppartisans)
comball2$news <- factor(comball2$news, levels= c("Sexual harassment",               
                                               "Leaking confidential information",
                                               "Cheating on spouse",
                                               "No Recent News",
                                               "Celebrated wedding anniversary",
                                               "Honored for public service" ) )
comball2$info <- factor(comball2$info, levels= c("Low", "Medium", "High"))
comball2$group <- as.factor(comball2$group)
```

```{r tidy=TRUE, warning=F, message=F}
gga3 <- ggplot(data = comball2, aes(x=points, y=interaction(news, info), group= info))+
  geom_errorbar(aes(xmax=cil, xmin=ciu), position=position_dodge(.9), width=0)+
  geom_vline(xintercept = 0, color="red") +
  geom_point(stat="identity", position="dodge")+
  theme_bw()+
  facet_grid(~group) +
  geom_hline(yintercept = c(6.5, 12.5))+
  ggtitle("Average Marginal Effect of News vs. No Recent News on Vote Choice \n By Information and Shared Partisanship")+
  xlab("Average Marginal Effect on Probability of Voting for the Candidate")+
  ylab("")+
  xlim(-.45,.3)+
  theme(plot.title = element_text(hjust = 0.5, size=8),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        #panel.border = element_blank(),
        #panel.grid.minor.y = element_blank(),
        legend.text = element_text(size=8),
        axis.text = element_text(size = 8),
        axis.title = element_text(size=8),
        strip.background = element_rect(
          fill="white", size=1, linetype="solid"))+
  scale_y_discrete(labels= rep(c("Sexual harassment",               
                                 "Leaking confidential information",
                                 "Cheating on spouse",
                                 "No Recent News",
                                 "Celebrated wedding anniversary",
                                 "Honored for public service" ) ,3))+
  annotate("text", x=-.3, y=5.6, label="Low Info", size=2.8)+  
  annotate("text", x=-.3, y=11.6, label="Medium Info", size=2.8)+
  annotate("text", x=-.3, y=17.6, label="High Info", size=2.8)
ggsave("appfigs/figure2facetcop.png", device = "png",width=7, height=4)

```
![](appfigs/figure2facetcop.png)

## Table A4


```{r tidy=TRUE}
## Note: recalls model objects from the main paper analysis above
htmlreg(list(i2.repvrepc, i2.repvdemc, 
             i2.demvdemc, i2.demvrepc), file = "appfigs/partisantable.doc",
        caption.above = T,
        custom.model.names = c("Rep Copartisan", "Rep Outpartisan",
                               "Demo Copartisan", "Dem Outpartisan"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment by Partisanship",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```

```{r tidy=TRUE, results="asis", echo=FALSE}
htmlreg(list(i2.repvrepc, i2.repvdemc, 
             i2.demvdemc, i2.demvrepc), 
        caption.above = T,
        custom.model.names = c("Rep Copartisan", "Rep Outpartisan",
                               "Dem Copartisan", "Dem Outpartisan"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment by Partisanship", include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))

```



## Table A5: Pooling positive and negative news

```{r tidy=TRUE}

## pooling negative and positive news
candlong$newsbinary <- as.factor(ifelse(candlong$news.p %in% 
                                          c("Recently celebrated wedding anniversary",
                                                               "Recently honored for public service"),
                                        "positive", ifelse(candlong$news.p %in% "No recent news", 
                                                           "neutral", "negative")))
candlong$newsbinary <- relevel(candlong$newsbinary, ref="neutral")

demspoolco <- subset(candlong, demrep == 1 & party.p == "Democrat")
demspoolco.p  <- lm_robust(chosen.p ~ newsbinary*factor(info.p),
                           data=demspoolco, 
                           se_type = "stata", 
                           clusters = demspoolco$ResponseId)

demspoolop <- subset(candlong, demrep == 1 & party.p == "Republican")
demspoolop.p  <- lm_robust(chosen.p ~ newsbinary*factor(info.p),
                           data=demspoolop, 
                           se_type = "stata", 
                           clusters = demspoolop$ResponseId)
repspoolco <- subset(candlong, demrep == 0 & party.p == "Republican")
repspoolco.p  <- lm_robust(chosen.p ~ newsbinary*factor(info.p),
                           data=repspoolco, 
                           se_type = "stata", 
                           clusters = repspoolco$ResponseId)

repspoolop <- subset(candlong, demrep == 0 & party.p == "Democrat")
repspoolop.p  <- lm_robust(chosen.p ~ newsbinary*factor(info.p),
                           data=repspoolop, 
                           se_type = "stata", 
                           clusters = repspoolop$ResponseId)
```

```{r tidy=TRUE}

htmlreg(list(demspoolco.p, demspoolop.p,
             repspoolco.p, repspoolop.p), file = "appfigs/partisanpool.doc",
        caption.above = T,
        custom.model.names = c("Dem Copartisan", "Dem Outpartisan",
                               "Rep Copartisan", "Rep Outpartisan"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment by Partisanship",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Negative",
                              'Positive',
                              "Medium Information",
                              "High Information",
                              "Negative X Medium",
                              "Positive X Medium",
                              "Negative X High",
                              "Positive X High"))
```

```{r tidy=TRUE, results="asis"}
htmlreg(list(demspoolco.p, demspoolop.p,
             repspoolco.p, repspoolop.p),
        caption.above = T,
        custom.model.names = c("Dem Copartisan", "Dem Outpartisan",
                               "Rep Copartisan", "Rep Outpartisan"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment by Partisanship",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Negative",
                              'Positive',
                              "Medium Information",
                              "High Information",
                              "Negative X Medium",
                              "Positive X Medium",
                              "Negative X High",
                              "Positive X High"))

```



## Figure A4 Heterogeneity by Partisan Strength

```{r tidy=TRUE}

candlong$scandalthree <- as.factor(ifelse(candlong$news.p %in% levels(candlong$news.p)[2:4], "negative",
                                          ifelse(candlong$news.p %in% levels(candlong$news.p)[1], "positive", "neutral")))

## Heterogeneity by Strength of PID- Republican candidates
repc <- subset(candlong,  party.p == "Republican")

## three-way
repc.mod  <- lm_robust(chosen.p ~ scandalthree*factor(partydtr)*factor(info.p), data=repc, 
                       se_type = "stata", 
                       clusters = repc$ResponseId)

p.neg.low <- predict(repc.mod, data.frame(scandalthree="negative", info.p=0, partydtr=1:7), interval="confidence")
p.pos.low <- predict(repc.mod, data.frame(scandalthree="positive", info.p=0, partydtr=1:7), interval="confidence")

p.neg.high <- predict(repc.mod, data.frame(scandalthree="negative", info.p=1, partydtr=1:7), interval="confidence")
p.pos.high <- predict(repc.mod, data.frame(scandalthree="positive", info.p=1, partydtr=1:7), interval="confidence")

png("appfigs/strofpid_rep.png", width = 10, height=4, units="in", res=300)
par(mfrow=c(1, 2))
plot(1:7, p.neg.low$fit[,1],
     ylim= c(0, 1), type="b", pch=15, lty=2, col="black",
     main = "Vote Choice for Republican Candidates \n Low Information",
     xlab= "Party ID: 1=Strong Democrat to 7=Strong Republican",
     ylab="Probability Vote for Candidate",
     cex.main=.8,
     cex.lab=.8)
points(1:7, p.pos.low$fit[,1],
       ylim= c(0, 1), type="b", pch= 16, col="gray", lty=2)
legend("bottomright", pch=c(15, 16), col = c("black", "gray"), c("Negative News", "Positive News"),
       cex=.65)

plot(1:7, p.neg.high$fit[,1],
     ylim= c(0, 1), type="b", pch=15, lty=2, col="black",
     main = "Vote Choice for Republican Candidates \n High Information",
     xlab= "Party ID: 1=Strong Democrat to 7=Strong Republican",
     ylab="Probability Vote for Candidate",
     cex.main=.8,
     cex.lab=.8)
points(1:7, p.pos.high$fit[,1],
       ylim= c(0, 1), type="b", pch= 16, col="gray", lty=2)
legend("bottomright", pch=c(15, 16), col = c("black", "gray"), c("Negative News", "Positive News"),
       cex=.65)
dev.off()
```

![](appfigs/strofpid_rep.png)\


```{r tidy=TRUE}
## Heterogeneity by Strength of PID- Democratic candidates

demc <- subset(candlong,  party.p == "Democrat")

## three-way
demc.mod  <- lm_robust(chosen.p ~ scandalthree*factor(partydtr)*factor(info.p), data=demc, 
                       se_type = "stata", 
                       clusters = demc$ResponseId)

p.neg.low <- predict(demc.mod, data.frame(scandalthree="negative", info.p=0, partydtr=1:7), interval="confidence")
p.pos.low <- predict(demc.mod, data.frame(scandalthree="positive", info.p=0, partydtr=1:7), interval="confidence")

p.neg.high <- predict(demc.mod, data.frame(scandalthree="negative", info.p=1, partydtr=1:7), interval="confidence")
p.pos.high <- predict(demc.mod, data.frame(scandalthree="positive", info.p=1, partydtr=1:7), interval="confidence")

png("appfigs/strofpid_dem.png", width = 10, height=4, units="in", res=300)
par(mfrow=c(1, 2))
plot(1:7, p.neg.low$fit[,1],
     ylim= c(0, 1), type="b", pch=15, lty=2, col="black",
     main = "Vote Choice for Democratic Candidates \n Low Information",
     xlab= "Party ID: 1=Strong Democrat to 7=Strong Republican",
     ylab="Probability Vote for Candidate",
     cex.main=.8,
     cex.lab=.8)
points(1:7, p.pos.low$fit[,1],
       ylim= c(0, 1), type="b", pch= 16, col="gray", lty=2)
legend("bottomleft", pch=c(15, 16), col = c("black", "gray"), c("Negative News", "Positive News"),
       cex=.65)

plot(1:7, p.neg.high$fit[,1],
     ylim= c(0, 1), type="b", pch=15, lty=2, col="black",
     main = "Vote Choice for Democratic Candidates \n High Information",
     xlab= "Party ID: 1=Strong Democrat to 7=Strong Republican",
     ylab="Probability Vote for Candidate",
     cex.main=.8,
     cex.lab=.8)
points(1:7, p.pos.high$fit[,1],
       ylim= c(0, 1), type="b", pch= 16, col="gray", lty=2)
legend("bottomleft", pch=c(15, 16), col = c("black", "gray"), c("Negative News", "Positive News"),
       cex=.65)
dev.off()
```

![](appfigs/strofpid_dem.png)\



## Figure A5: Variation in Effects of All Attributes Moving from Medium to High Information Environments 

```{r tidy=TRUE}

medhigh <- subset(candlong, info.p > 0)
medhigh$highinfo <- ifelse(medhigh$info.p == 1, 1, 0)

mymargplotmh <-function(mod, mytitle, xlabel, var, var2, newlevs){
  diffs <- c()
  ci.l <- c()
  ci.u <- c()
  
  levs <- levels(var)[levels(var) != "Not Shown"]
  
  for(i in 2:length(levs)){
    which1 <- paste(var2, levs[i],":highinfo", sep="")
    info.high <- coef(mod)["highinfo"]
    int.coef <- coef(mod)[which1]
    diffs[i] <- info.high + int.coef
    comp.ses <- sqrt(vcov(mod)["highinfo","highinfo"] + 
                       vcov(mod)[which1,which1] + 2*vcov(mod)["highinfo", which1])
    ci.l[i] <- (info.high + int.coef) - 1.96*comp.ses
    ci.u[i] <- (info.high + int.coef) + 1.96*comp.ses
  }
  diffs[1] <- info.high
  ci.l[1] <- info.high - 1.96*mod$std.error["highinfo"]
  ci.u[1] <- info.high + 1.96*mod$std.error["highinfo"]
  #par(oma = c(1, 10, 1, .5))
  plot(x=diffs, y=1:length(diffs), pch = 15, 
       main = mytitle,
       cex.main = .7, ylab="", yaxt = "n", 
       xlim = c(-.2, .2),
       ylim = c(0, (length(diffs) + 1)),
       xlab = xlabel, cex.lab = .8, cex.axis = .8)
  abline(v= 0, col="red")
  for(i in 1:length(diffs)){
    lines(c(ci.l[i], ci.u[i]), c(i,i), lwd=1.5)
  }
  
  axis(2,1:length(diffs), 
       newlevs, 
       cex.axis=.65, las=1)
}
```

```{r tidy=TRUE}
## Abortion
absats <- subset(medhigh, abortion.p != "Not Shown")
ab  <- lm_robust(chosen.p ~ abortion.p*highinfo,
                 absats, se_type = "stata", 
                 clusters = absats$ResponseId)
ablevs <- c("Always", "Never", "When life in danger")
png("appfigs/abortion_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ab,"Marginal Effect of Info on Vote Choice  \n Abortion: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", absats$abortion.p, "abortion.p",
             newlevs= ablevs)
dev.off()


## Spending
spsats <- subset(medhigh, spending.p != "Not Shown")
sp  <- lm_robust(chosen.p ~ spending.p*highinfo,
                 spsats, se_type = "stata", 
                 clusters = spsats$ResponseId)

splevs <- c("Decrease-large", "Decrease-small", "Increase-large", "Increase-small", "No change")
png("appfigs/sp_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(sp,"Marginal Effect of Info on Vote Choice  \n Spending: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", spsats$spending.p, "spending.p",
             newlevs= splevs)
dev.off()


## Party
pasats <- subset(medhigh, party.p != "Not Shown")
pa  <- lm_robust(chosen.p ~ party.p*highinfo,
                 pasats, se_type = "stata", 
                 clusters = pasats$ResponseId)
palevs <- levels(candlong$party.p)
png("appfigs/pa_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(pa,"Marginal Effect of Info on Vote Choice  \n Party: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", pasats$party.p, "party.p",
             newlevs= palevs)
dev.off()

## newsbinary
medhigh$scandalthree <- as.factor(ifelse(medhigh$news.p %in% levels(medhigh$news.p)[2:4], "Negative news",
                                         ifelse(medhigh$news.p %in% levels(medhigh$news.p)[5:6], "Positive News", NA)))
scsats <- subset(medhigh, is.na(scandalthree)==F)
sc  <- lm_robust(chosen.p ~ scandalthree*highinfo,
                 scsats, se_type = "stata", 
                 clusters = scsats$ResponseId)
sclevs <- levels(medhigh$scandalthree)
png("appfigs/sc_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(sc,"Marginal Effect of Info on Vote Choice  \n Scandal Binary: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", scsats$scandalthree, "scandalthree",
             newlevs= sclevs)
dev.off()

## Immigration
imsats <- subset(medhigh, immigration.p != "Not Shown")
im  <- lm_robust(chosen.p ~ immigration.p*highinfo,
                 imsats, se_type = "stata", 
                 clusters = imsats$ResponseId)
imlevs <- c("Opposes pathway", "Supports pathway")
png("appfigs/im_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(im,"Marginal Effect of Info on Vote Choice  \n Immigration: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", imsats$immigration.p, "immigration.p",
             newlevs= imlevs)
dev.off()

# news, party, imm, ab, sp, age, race, gender
## Race
rasats <- subset(medhigh, race.p != "Not Shown")
ra  <- lm_robust(chosen.p ~ race.p*highinfo,
                 rasats, se_type = "stata", 
                 clusters = rasats$ResponseId)
ralevs <- c("Asian", "Black", "Hispanic", "White")
png("appfigs/ra_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ra,"Marginal Effect of Info on Vote Choice  \n Race: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", rasats$race.p, "race.p",
             newlevs= ralevs)
dev.off()

## Gender
gesats <- subset(medhigh, gender.p != "Not Shown")
ge  <- lm_robust(chosen.p ~ gender.p*highinfo,
                 gesats, se_type = "stata", 
                 clusters = gesats$ResponseId)
gelevs <- c("Female", "Male")
png("appfigs/ge_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ge,"Marginal Effect of Info on Vote Choice  \n Gender: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", gesats$gender.p, "gender.p",
             newlevs= gelevs)
dev.off()


## Age
agsats <- subset(medhigh, age.p != "Not Shown")
ag  <- lm_robust(chosen.p ~ age.p*highinfo,
                 agsats, se_type = "stata", 
                 clusters = agsats$ResponseId)
aglevs <- levels(candlong$age.p)[-10]
png("appfigs/ag_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ag,"Marginal Effect of Info on Vote Choice  \n Age: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", agsats$age.p, "age.p",
             newlevs= aglevs)
dev.off()

## Religion
resats <- subset(medhigh, religion.p != "Not Shown")
re  <- lm_robust(chosen.p ~ religion.p*highinfo,
                 resats, se_type = "stata", 
                 clusters = resats$ResponseId)
relevs <- c("Catholic", "Evangelical Christian", "Jewish", "Not very religious", "Protestant")
png("appfigs/re_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(re,"Marginal Effect of Info on Vote Choice  \n Religion: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", resats$religion.p, "religion.p",
             newlevs= relevs)
dev.off()

## Profession
prsats <- subset(medhigh, profession.p != "Not Shown")
pr  <- lm_robust(chosen.p ~ profession.p*highinfo,
                 prsats, se_type = "stata", 
                 clusters = prsats$ResponseId)
prlevs <- levels(candlong$profession.p)[-6]
png("appfigs/pr_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(pr,"Marginal Effect of Info on Vote Choice  \n Profession: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", prsats$profession.p, "profession.p",
             newlevs= prlevs)
dev.off()

## News
nesats <- subset(medhigh, news.p != "Not Shown")
ne  <- lm_robust(chosen.p ~ news.p*highinfo,
                 nesats, se_type = "stata", 
                 clusters = nesats$ResponseId)
nelevs <- c("No recent news", "Cheating on Spouse", "Leaking Confidential Info", "Sexual Harassment",
            "Wedding Anniversary", "Honored Public Service")
png("appfigs/ne_sat.png", width = 5, height = 4, units="in", res=300)
par(oma = c(1, 3, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ne,"Marginal Effect of Info on Vote Choice  \n News: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", nesats$news.p, "news.p",
             newlevs= nelevs)
dev.off()
```

![](appfigs/pa_sat.png){width=40%}\ ![](appfigs/sc_sat.png){width=40%}\
![](appfigs/im_sat.png){width=40%}\ ![](appfigs/ra_sat.png){width=40%}\
![](appfigs/ge_sat.png){width=40%}\ ![](appfigs/ag_sat.png){width=40%}\
![](appfigs/re_sat.png){width=40%}\ ![](appfigs/pr_sat.png){width=40%}\
![](appfigs/ne_sat.png){width=40%}\ ![](appfigs/abortion_sat.png){width=40%}\



## Figure A6: Variation in Effects of “Shared” Positions and Attribute Valence, Moving from Medium to High Information Environments 

The code below creates factor variable indicators of whether a respondent shares a position / partisanship with the candidate.
```{r tidy=TRUE}
## sharing views on abortion
candlong$shareabortionf <- as.factor(ifelse((candlong$abortion.p == "A woman should always be able to obtain an abortion" &
                                    candlong$abortion == "A woman should always be able to obtain an abortion") | 
                                   (candlong$abortion.p == "Abortion should never be permitted" &
                                      candlong$abortion == "Abortion should never be permitted") |
                                   (candlong$abortion.p == "Permit abortion only when the life of the mother is indanger" &
                                      candlong$abortion == "Permit abortion only when the life of the mother is in danger"), "Shares Abortion", 
                                  "Does Not Share Abortion"))

## shared views on immigration
candlong$shareimmigrationf <- as.factor(ifelse((candlong$immigration.p == "Opposes a pathway to citizenship for undocumented immigrants" &
                                       candlong$immigration == "Oppose pathway to citizenship") | 
                                      (candlong$immigration.p == "Supports a pathway for citizenship for undocumented immigrants" &
                                         candlong$immigration == "Support pathway to citizenship"), "Shares Immigration", 
                                     "Does Not Share Immigration"))


## shared views on spending
candlong$sharespendingf <- as.factor(ifelse((candlong$spending.p %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount") &
                                    candlong$spending %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount")) | 
                                   (candlong$spending.p == "No change to spending" &
                                      candlong$spending == "No change to spending") |
                                   (candlong$spending.p %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount") &
                                      candlong$spending %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount")), "Shares Spending", 
                                 "Does Not Share Spending"))


## Defining copartisanship
candlong$copartisanf <- as.factor(ifelse((candlong$party.p == "Democrat" &
                              candlong$dem == 1) |
                             (candlong$party.p == "Republican" &
                                candlong$rep == 1), "Copartisan", "Not Copartisan"))
candlong$copartisanf[is.na(candlong$demrep) == T] <- NA
```

```{r tidy=TRUE}
medhigh <- subset(candlong, info.p > 0)
medhigh$highinfo <- ifelse(medhigh$info.p == 1, 1, 0)

## Share Abortion
absats <- subset(medhigh, abortion.p != "Not Shown")
ab  <- lm_robust(chosen.p ~ shareabortionf*highinfo,
                 absats, se_type = "stata", 
                 clusters = absats$ResponseId)
ablevs <- levels(medhigh$shareabortionf)
png("appfigs/sh_abortion_sat.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ab,"Marginal Effect of Info on Vote Choice  \n Shares Abortion Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", absats$shareabortionf, "shareabortionf",
             newlevs= ablevs)
dev.off()

## Share Spending
spsats <- subset(medhigh, spending.p != "Not Shown")
sp  <- lm_robust(chosen.p ~ sharespendingf*highinfo,
                 spsats, se_type = "stata", 
                 clusters = spsats$ResponseId)

splevs <- levels(medhigh$sharespendingf)
png("appfigs/sh_sp_sat.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(sp,"Marginal Effect of Info on Vote Choice  \n Shares Spending Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", spsats$sharespendingf, "sharespendingf",
             newlevs= splevs)
dev.off()


## Shares Party
pasats <- subset(medhigh, party.p != "Not Shown" )
pa  <- lm_robust(chosen.p ~ copartisanf*highinfo,
                 pasats, se_type = "stata", 
                 clusters = pasats$ResponseId)
palevs <- levels(medhigh$copartisanf)
png("appfigs/sh_pa_sat.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(pa,"Marginal Effect of Info on Vote Choice  \n Shares Partisanship: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", pasats$copartisanf, "copartisanf",
             newlevs= palevs)
dev.off()

## Shares Immigration

imsats <- subset(medhigh, immigration.p != "Not Shown" )
im  <- lm_robust(chosen.p ~ shareimmigrationf*highinfo,
                 imsats, se_type = "stata", 
                 clusters = imsats$ResponseId)
imlevs <- levels(medhigh$shareimmigrationf)
png("appfigs/sh_im_sat.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(im,"Marginal Effect of Info on Vote Choice  \n Shares Immigration Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", imsats$shareimmigrationf, "shareimmigrationf",
             newlevs= imlevs)
dev.off()
```

![](appfigs/sh_abortion_sat.png){width=40%}\ ![](appfigs/sh_sp_sat.png){width=40%}\
![](appfigs/sh_pa_sat.png){width=40%}\ ![](appfigs/sh_im_sat.png){width=40%}\

```{r tidy=TRUE}
## Controlling attribute location

## Share Abortion
absats <- subset(medhigh, abortion.p != "Not Shown" & abortion.n < 4)
ab  <- lm_robust(chosen.p ~ shareabortionf*highinfo,
                 absats, se_type = "stata", 
                 clusters = absats$ResponseId)


ablevs <- levels(medhigh$shareabortionf)
png("appfigs/sh_abortion_sath.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(ab,"High Attributes: Marginal Effect of Info on Vote Choice  \n Shares Abortion Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", absats$shareabortionf, "shareabortionf",
             newlevs= ablevs)
dev.off()

## Share Spending
spsats <- subset(medhigh, spending.p != "Not Shown" & spending.n < 4)
sp  <- lm_robust(chosen.p ~ sharespendingf*highinfo,
                 spsats, se_type = "stata", 
                 clusters = spsats$ResponseId)

splevs <- levels(medhigh$sharespendingf)
png("appfigs/sh_sp_sath.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(sp,"High Attributes: Marginal Effect of Info on Vote Choice  \n Shares Spending Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", spsats$sharespendingf, "sharespendingf",
             newlevs= splevs)
dev.off()



## Shares Immigration
imsats <- subset(medhigh, immigration.p != "Not Shown" & immigration.n < 4)
im  <- lm_robust(chosen.p ~ shareimmigrationf*highinfo,
                 imsats, se_type = "stata", 
                 clusters = imsats$ResponseId)
imlevs <- levels(medhigh$shareimmigrationf)
png("appfigs/sh_im_sath.png", width = 5, height = 3, units="in", res=300)
par(oma = c(1, 5, 1, .5), mar = c(4,4,2,1), mfrow = c(1,1))
mymargplotmh(im,"High Attributes: Marginal Effect of Info on Vote Choice  \n Shares Immigration Position: High vs. Medium Info", 
             "Difference in Probability of Voting for Candidate", imsats$shareimmigrationf, "shareimmigrationf",
             newlevs= imlevs)
dev.off()

```


![](appfigs/sh_abortion_sath.png){width=40%} ![](appfigs/sh_sp_sath.png){width=40%}\
![](appfigs/sh_im_sath.png){width=40%}\

## Table A6 Morality Main Results

```{r tidy=TRUE}
m2  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)

## Column 2: Limit analysis to high vs. medium information environments
medhigh <- subset(candlong, info.p > 0)

m2mh  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                 medhigh, se_type = "stata", 
                 clusters = medhigh$ResponseId)
```

```{r include = T, tidy=T}
## Code below produces a regression table
htmlreg(list(m2, m2mh), file = "appfigs/tablea6.doc",
        caption.above = T,
        custom.model.names = c("Morals",  
                               "Morals: Medium and High Only"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```


```{r echo=FALSE, tidy=T, results="asis"}
## Code below produces a regression table
htmlreg(list(m2, m2mh),
        caption.above = T,
        custom.model.names = c("Morals",  
                               "Morals: Medium and High Only"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Information Environment",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```



## Figure A7: Partisan subsets for morality

```{r tidy=TRUE}
repvrepc <- subset(candlong, demrep == 0 &
                     party.p == "Republican")
m2.repvrepc  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                          data=repvrepc, 
                          se_type = "stata", 
                          clusters = repvrepc$ResponseId)

repvdemc <- subset(candlong, demrep == 0 &
                     party.p == "Democrat")
m2.repvdemc  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                          data=repvdemc, 
                          se_type = "stata", 
                          clusters = repvdemc$ResponseId)

demvrepc <- subset(candlong, demrep == 1 &
                     party.p == "Republican")
m2.demvrepc  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                          data=demvrepc, 
                          se_type = "stata", 
                          clusters = demvrepc$ResponseId)

demvdemc <- subset(candlong, demrep == 1 &
                     party.p == "Democrat")
m2.demvdemc  <- lm_robust(moral.ps ~ news.p*factor(info.p),
                          data=demvdemc, 
                          se_type = "stata", 
                          clusters = demvdemc$ResponseId)

## Partisan facet plot
retdf <- function(i2, comparison){
  diffs.low <- coef(i2)[2:6]
  low.cis <- confint(i2)[2:6,]
  diffs.med <- c()
  ci.l.med <- c()
  ci.u.med <- c()
  for(i in 2:length(levels(candlong$news.p))){
    medint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)0.5", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    med.main <- coef(i2)[scan]
    med.int <- coef(i2)[medint]
    diffs.med[(i-1)] <- med.main + med.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[medint,medint] + 2*vcov(i2)[scan, medint])
    ci.l.med[(i-1)] <- (med.main + med.int) - 1.96*comp.ses
    ci.u.med[(i-1)] <- (med.main + med.int) + 1.96*comp.ses
  }
  med.cis <- cbind(ci.l.med, ci.u.med)
  diffs.high <- c()
  ci.l.high <- c()
  ci.u.high <- c()
  for(i in 2:length(levels(candlong$news.p))){
    highint <- paste("news.p", levels(candlong$news.p)[i],":factor(info.p)1", sep="")
    scan <- paste("news.p", levels(candlong$news.p)[i], sep="")
    high.main <- coef(i2)[scan]
    high.int <- coef(i2)[highint]
    diffs.high[(i-1)] <- high.main + high.int
    comp.ses <- sqrt(vcov(i2)[scan,scan] + 
                       vcov(i2)[highint,highint] + 2*vcov(i2)[scan, highint])
    ci.l.high[(i-1)] <- (high.main + high.int) - 1.96*comp.ses
    ci.u.high[(i-1)] <- (high.main + high.int) + 1.96*comp.ses
  }
  high.cis <- cbind(ci.l.high, ci.u.high)
  
  ## re-order levels
  diffs.low <- diffs.low[c(3,2,1,4,5)]
  diffs.med <- diffs.med[c(3,2,1,4,5)]
  diffs.high <- diffs.high[c(3,2,1,4,5)]
  low.cis <- low.cis[c(3,2,1,4,5),]
  med.cis <- med.cis[c(3,2,1,4,5),]
  high.cis <- high.cis[c(3,2,1,4,5),]
  news2 <- c("Sexual harassment",               
             "Leaking confidential information",
             "Cheating on spouse",
             "No Recent News",
             "Celebrated wedding anniversary",
             "Honored for public service" )   
  x <- data.frame(points = c(diffs.low[1:3], 0, diffs.low[4:5],
                             diffs.med[1:3], 0, diffs.med[4:5],
                             diffs.high[1:3], 0, diffs.high[4:5]),
                  news = rep(news2, 3),
                  cil = c(low.cis[1:3,1], 0,low.cis[4:5,1],
                          med.cis[1:3,1], 0,med.cis[4:5,1],
                          high.cis[1:3,1], 0, high.cis[4:5,1]),
                  ciu = c(low.cis[1:3,2], 0,low.cis[4:5,2],
                          med.cis[1:3,2], 0,med.cis[4:5,2],
                          high.cis[1:3,2], 0, high.cis[4:5,2]),
                  info = c(rep("Low", 6),rep("Medium",6),rep("High", 6)),
                  group = comparison)
  return(x)
}


df.demvdemc <-retdf(i2=m2.demvdemc, comparison = "Democratic Respondent \n Democratic Candidate")
df.demvrepc <-retdf(i2=m2.demvrepc, comparison = "Democratic Respondent \n Republican Candidate")
df.repvdemc <-retdf(i2=m2.repvdemc, comparison = "Republican Respondent \n Democratic Candidate")
df.repvrepc <-retdf(i2=m2.repvrepc, comparison = "Republican Respondent \n Republican Candidate")

comball <- rbind(df.demvdemc, df.demvrepc,df.repvdemc,df.repvrepc)
comball$news <- factor(comball$news, levels= c("Sexual harassment",               
                                               "Leaking confidential information",
                                               "Cheating on spouse",
                                               "No Recent News",
                                               "Celebrated wedding anniversary",
                                               "Honored for public service" ) )
comball$info <- factor(comball$info, levels= c("Low", "Medium", "High"))
comball$group <- as.factor(comball$group)
```

```{r tidy=TRUE, warning=F, message=F}
ggmor <- ggplot(data = comball, aes(x=points, y=interaction(news, info), group= info))+
  geom_errorbar(aes(xmax=cil, xmin=ciu), position=position_dodge(.9), width=0)+
  geom_vline(xintercept = 0, color="red") +
  geom_point(stat="identity", position="dodge")+
  theme_bw()+
  facet_grid(~group) +
  geom_hline(yintercept = c(6.5, 12.5))+
  ggtitle("Average Marginal Effect of News vs. No Recent News on Perceived Morality \n By Information and Respondent and Candidate Partisanship")+
  xlab("Average Marginal Effect on Perceived Morality")+
  ylab("")+
  xlim(-.45,.3)+
  theme(plot.title = element_text(hjust = 0.5, size=8),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        #panel.border = element_blank(),
        #panel.grid.minor.y = element_blank(),
        legend.text = element_text(size=8),
        axis.text = element_text(size = 8),
        axis.title = element_text(size=8),
        strip.background = element_rect(
          fill="white", size=1, linetype="solid"))+
  scale_y_discrete(labels= rep(c("Sexual harassment",               
                                 "Leaking confidential information",
                                 "Cheating on spouse",
                                 "No Recent News",
                                 "Celebrated wedding anniversary",
                                 "Honored for public service" ) ,3))+
  annotate("text", x=-.3, y=5.6, label="Low Info", size=2.8)+  
  annotate("text", x=-.3, y=11.6, label="Medium Info", size=2.8)+
  annotate("text", x=-.3, y=17.6, label="High Info", size=2.8)
ggsave("appfigs/partmorality.png", device = "png",width=10, height=4)
```

![](appfigs/partmorality.png)\




## Table A7 Shared Policy Analysis

```{r tidy=TRUE}
## sharing views on abortion
candlong$shareabortion <- ifelse((candlong$abortion.p == "A woman should always be able to obtain an abortion" &
                                    candlong$abortion == "A woman should always be able to obtain an abortion") | 
                                   (candlong$abortion.p == "Abortion should never be permitted" &
                                      candlong$abortion == "Abortion should never be permitted") |
                                   (candlong$abortion.p == "Permit abortion only when the life of the mother is indanger" &
                                      candlong$abortion == "Permit abortion only when the life of the mother is in danger"), 1, 0)

## shared views on immigration
candlong$shareimmigration <- ifelse((candlong$immigration.p == "Opposes a pathway to citizenship for undocumented immigrants" &
                                       candlong$immigration == "Oppose pathway to citizenship") | 
                                      (candlong$immigration.p == "Supports a pathway for citizenship for undocumented immigrants" &
                                         candlong$immigration == "Support pathway to citizenship"), 1, 0)


## shared views on spending
candlong$sharespending <- ifelse((candlong$spending.p %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount") &
                                    candlong$spending %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount")) | 
                                   (candlong$spending.p == "No change to spending" &
                                      candlong$spending == "No change to spending") |
                                   (candlong$spending.p %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount") &
                                      candlong$spending %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount")), 1, 0)

## Total number of shared policies, 2 and 3 combined
candlong$sharedpolicies <- ifelse((candlong$shareabortion == 1 &
                                     candlong$shareimmigration == 1 &
                                     candlong$sharespending == 1), 2,
                                  ifelse(candlong$shareabortion == 0 &
                                           candlong$shareimmigration == 1 &
                                           candlong$sharespending == 1, 2,
                                         ifelse(candlong$shareabortion == 1 &
                                                  candlong$shareimmigration == 0 &
                                                  candlong$sharespending == 1, 2,
                                                ifelse(candlong$shareabortion == 1 &
                                                         candlong$shareimmigration == 1 &
                                                         candlong$sharespending == 0, 2,
                                                       ifelse(candlong$shareabortion == 1 &
                                                                candlong$shareimmigration == 0 &
                                                                candlong$sharespending == 0, 1,
                                                              ifelse(candlong$shareabortion == 0 &
                                                                       candlong$shareimmigration == 1 &
                                                                       candlong$sharespending == 0, 1,
                                                                     ifelse(candlong$shareabortion == 0 &
                                                                              candlong$shareimmigration == 0 &
                                                                              candlong$sharespending == 1, 1,
                                                                            ifelse(candlong$shareabortion == 0 &
                                                                                     candlong$shareimmigration == 0 &
                                                                                     candlong$sharespending == 0, 0, NA))))))))

kable(prop.table(table(candlong$sharedpolicies[candlong$info.p==.5])), col.names = c("Shared Policies", "Proportion"))
kable(prop.table(table(candlong$sharedpolicies[candlong$info.p==1])), col.names = c("Shared Policies", "Proportion"))

```

```{r tidy=TRUE}

## Regression: Vote Choice on Number of Shared Policies
p2  <- lm_robust(chosen.p ~ news.p*factor(info.p) + factor(sharedpolicies),
                 candlong, se_type = "stata", 
                 clusters = candlong$ResponseId)


htmlreg(list(p2), file = "appfigs/tablesharedpol.doc",
        caption.above = T,
        custom.model.names = c("Vote Choice"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Number of Shared Policies",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Shares 1 Policy Position (vs. 0)",
                              "Shares More than 1 Policy Position (vs. 0)",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))

```

```{r tidy=TRUE, echo=FALSE, results="asis"}
htmlreg(list(p2), 
        caption.above = T,
        custom.model.names = c("Vote Choice: Medium Information Only"),
        stars = c(0.001, 0.01, 0.05, 0.10),
        caption = "Regression on Interaction between News and Number of Shared Policies",
        scriptsize = TRUE, include.ci = F,
        custom.coef.names = c("Intercept",
                              "Cheating on spouse",
                              "Leaking confidential information",
                              "Sexual harassment",
                              "Wedding anniversary",
                              "Honored public service",
                              "Medium Information",
                              "High Information",
                              "Shares 1 Policy Position (vs. 0)",
                              "Shares More than 1 Policy Position (vs. 0)",
                              "Medium Information X Cheating on spouse",
                              "Medium Information X Leaking confidential information",
                              "Medium Information X Sexual harassment",
                              "Medium Information X Wedding anniversary",
                              "Medium Information X Honored public service",
                              "High Information X Cheating on spouse",
                              "High Information X Leaking confidential information",
                              "High Information X Sexual harassment",
                              "High Information X Wedding anniversary",
                              "High Information X Honored public service"))
```

## Figure A8

```{r tidy=TRUE}
## subset high information environment only
fullinfo <- subset(candlong, info.p == 1)

## regression vote choice on all attributes
ai3  <- lm_robust(chosen.p ~  party.p +
                    news.p +
                    gender.p +
                    relevel(race.p, ref = "White") +
                    relevel(age.p, ref = "74") +
                    profession.p +
                    relevel(religion.p, ref = "Not very religious") +
                    immigration.p +
                    abortion.p +
                    relevel(spending.p, ref = "No change to spending"),
                  fullinfo, se_type = "stata", 
                  clusters = fullinfo$ResponseId)

## Plotting
ests <- c(coef(ai3)[2], 0,
          coef(ai3)[3:7], 0,
          coef(ai3)[8], 0,
          coef(ai3)[9:11], 0,
          coef(ai3)[12:19], 0,
          coef(ai3)[20:24],0,
          coef(ai3)[25:28],0,
          coef(ai3)[29],0,
          coef(ai3)[30:31],0,
          coef(ai3)[32:35],0)
cil <- c(confint(ai3)[2,1], 0,
         confint(ai3)[3:7, 1], 0,
         confint(ai3)[8,1], 0,
         confint(ai3)[9:11,1], 0,
         confint(ai3)[12:19,1], 0,
         confint(ai3)[20:24,1],0,
         confint(ai3)[25:28, 1],0,
         confint(ai3)[29, 1],0,
         confint(ai3)[30:31, 1],0,
         confint(ai3)[32:35, 1],0)
ciu <- c(confint(ai3)[2,2], 0,
         confint(ai3)[3:7, 2], 0,
         confint(ai3)[8,2], 0,
         confint(ai3)[9:11,2], 0,
         confint(ai3)[12:19,2], 0,
         confint(ai3)[20:24,2],0,
         confint(ai3)[25:28, 2],0,
         confint(ai3)[29, 2],0,
         confint(ai3)[30:31, 2],0,
         confint(ai3)[32:35, 2],0)

png("appfigs/amceshighinfo.png", width = 7, height = 8, units="in", res=300)
par(mar = c(4, 13, 4, 2))
plot(ests, 1:length(ests), xlim = c(-.4, .4),
     pch = 20, yaxt = "n", ylab = "", bty =  "n",
     xlab = "AMCE on Pr(Chosen) and 95% Confidence Interval",
     cex.main = .7, cex.lab = .8, cex.axis = .8,
     main = "Average Marginal Component Effect on Pr(Chosen) \n High Information Environment Only")
for(i in 1:length(ests)){
  lines(c(cil[i], ciu[i]), c(i,i))
}
abline(h = c(2.5, 8.5, 10.5, 14.5, 23.5, 29.5, 34.5, 36.5, 39.5), col = "gray")
abline(v=0, col="red")
points(ests, 1:length(ests), cex = 1, pch = 20)
axis(2, 1:length(ests),
     c("Republican", "Democrat", 
       "Recently accused of cheating on spouse",                               
       "Recently accused of leaking confidential information",                 
       "Recently accused of sexual harassment",                                
       "Recently celebrated wedding anniversary",                              
       "Recently honored for public service",
       "No recent news",
       
       "Male", "Female", 
       "Asian", "Black", "Hispanic", "White", 
       "28", "34", "40", "46", "52", "58", "62","68", "74", 
       "Doctor", "Farmer", "Lawyer", "Military", "Teacher", "Business Owner",
       "Catholic","Evangelical", "Jewish",  "Protestant", "Not very religious",
       "Supports citizenship pathway","Opposes citizenship pathway",
       
       "Abortion never permitted",
       "Permit abortion only when life of mother in danger",
       "Always be able to obtain abortion",
       "Decrease spending large amount",
       "Decrease spending small amount",
       "Increase spending large amount",
       "Increase spending small amount",
       "No change to spending"), las =1, cex.axis = .55, tick = T)
dev.off()
```

![](appfigs/amceshighinfo.png)\


## Figure A9: accounts for shared views

```{r tidy=TRUE}
## sharing views on abortion
candlong$shareabortion <- ifelse((candlong$abortion.p == "A woman should always be able to obtain an abortion" &
                                    candlong$abortion == "A woman should always be able to obtain an abortion") | 
                                   (candlong$abortion.p == "Abortion should never be permitted" &
                                      candlong$abortion == "Abortion should never be permitted") |
                                   (candlong$abortion.p == "Permit abortion only when the life of the mother is indanger" &
                                      candlong$abortion == "Permit abortion only when the life of the mother is in danger"), 1, 0)

## shared views on immigration
candlong$shareimmigration <- ifelse((candlong$immigration.p == "Opposes a pathway to citizenship for undocumented immigrants" &
                                       candlong$immigration == "Oppose pathway to citizenship") | 
                                      (candlong$immigration.p == "Supports a pathway for citizenship for undocumented immigrants" &
                                         candlong$immigration == "Support pathway to citizenship"), 1, 0)


## shared views on spending
candlong$sharespending <- ifelse((candlong$spending.p %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount") &
                                    candlong$spending %in% c("Decrease spending a large amount",
                                                             "Decrease spending a small amount")) | 
                                   (candlong$spending.p == "No change to spending" &
                                      candlong$spending == "No change to spending") |
                                   (candlong$spending.p %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount") &
                                      candlong$spending %in% c("Increase spending a large amount",
                                                               "Increase spending a small amount")), 1, 0)

## subset high information environment only
fullinfo <- subset(candlong, info.p == 1)

## regression vote choice on all attributes/shared issues
si3  <- lm_robust(chosen.p ~  party.p +
                    news.p +
                    gender.p +
                    relevel(race.p, ref = "White") +
                    relevel(age.p, ref = "74") +
                    profession.p +
                    relevel(religion.p, ref = "Not very religious") +
                    shareimmigration +
                    shareabortion +
                    sharespending,
                  fullinfo, se_type = "stata", 
                  clusters = fullinfo$ResponseId)
summary(si3)$coefficients["shareimmigration",]
summary(si3)$coefficients["shareabortion",]
summary(si3)$coefficients["sharespending",]


## partisans regression vote choice on all attributes/shared issues
partsfi <- subset(candlong, info.p == 1 & (dem == 1 | rep == 1))
partsfi$copartisan <- ifelse((partsfi$party.p == "Democrat" &
                                partsfi$dem == 1) |
                               (partsfi$party.p == "Republican" &
                                  partsfi$rep == 1), 1, 0)

psi3  <- lm_robust(chosen.p ~  copartisan +
                     news.p +
                     gender.p +
                     relevel(race.p, ref = "White") +
                     relevel(age.p, ref = "74") +
                     profession.p +
                     relevel(religion.p, ref = "Not very religious") +
                     shareimmigration +
                     shareabortion +
                     sharespending,
                   partsfi, se_type = "stata", 
                   clusters = partsfi$ResponseId)
summary(psi3)$coefficients["copartisan",]
summary(psi3)$coefficients["shareimmigration",]
summary(psi3)$coefficients["shareabortion",]
summary(psi3)$coefficients["sharespending",]


estsp <- c(coef(psi3)[2], 0,
           coef(psi3)[3:7], 0,
           coef(psi3)[8], 0,
           coef(psi3)[9:11], 0,
           coef(psi3)[12:19], 0,
           coef(psi3)[20:24],0,
           coef(psi3)[25:28],0,
           coef(psi3)[29],0,
           coef(psi3)[30],0,
           coef(psi3)[31],0)
cilp <- c(confint(psi3)[2,1], 0,
          confint(psi3)[3:7, 1], 0,
          confint(psi3)[8,1], 0,
          confint(psi3)[9:11,1], 0,
          confint(psi3)[12:19,1], 0,
          confint(psi3)[20:24,1],0,
          confint(psi3)[25:28, 1],0,
          confint(psi3)[29, 1],0,
          confint(psi3)[30, 1],0,
          confint(psi3)[31, 1],0)
ciup <- c(confint(psi3)[2,2], 0,
          confint(psi3)[3:7, 2], 0,
          confint(psi3)[8,2], 0,
          confint(psi3)[9:11,2], 0,
          confint(psi3)[12:19,2], 0,
          confint(psi3)[20:24,2],0,
          confint(psi3)[25:28, 2],0,
          confint(psi3)[29, 2],0,
          confint(psi3)[30, 2],0,
          confint(psi3)[31, 2],0)
```

```{r tidy=TRUE}
png("appfigs/amceshighinfopart.png", width = 7, height = 8, units="in", res=300)
par(mar = c(4, 13, 4, 2), mfrow = c(1,1))
plot(estsp, 1:length(estsp), xlim = c(-.4, .4),
     pch = 20, yaxt = "n", ylab = "", bty =  "n",
     xlab = "Effect on Pr(Chosen) and 95% Confidence Interval",
     cex.main = .7, cex.lab = .8, cex.axis = .8,
     main = "Effect on Pr(Chosen) \n High Information Environment, Partisans Only")
for(i in 1:length(estsp)){
  lines(c(cilp[i], ciup[i]), c(i,i))
}
abline(h = c(2.5, 8.5, 10.5, 14.5, 23.5, 29.5, 34.5, 36.5, 38.5), col = "gray")
abline(v=0, col="red")
points(estsp, 1:length(estsp), cex = 1, pch = 20)
axis(2, 1:length(estsp),
     c("Copartisan", "Out-Party", 
       "Recently accused of cheating on spouse",                               
       "Recently accused of leaking confidential information",                 
       "Recently accused of sexual harassment",                                
       "Recently celebrated wedding anniversary",                              
       "Recently honored for public service",
       "No recent news",
       
       "Male", "Female", 
       "Asian", "Black", "Hispanic", "White", 
       "28", "34", "40", "46", "52", "58", "62","68", "74", 
       "Doctor", "Farmer", "Lawyer", "Military", "Teacher", "Business Owner",
       "Catholic","Evangelical", "Jewish",  "Protestant", "Not very religious",
       "Shares Immigration Position","Does Not Share Immigration Position",
       
       "Shares Abortion Position", "Does Not Share Abortion Position",
       "Shares Spending Position", "Does Not Share Spending Position"), las =1, cex.axis = .55, tick = T)
dev.off()
```
![](appfigs/amceshighinfopart.png)




## Figures A10-A12

```{r tidy=TRUE}

png("appfigs/moraldist.png", width = 6, height = 4, units="in", res=300)
barplot(prop.table(table(candlong$moral.ps)),
        ylim = c(0, .4),
        main = "Candidate has good morals",
        ylab= "Proportion of Respondents",
        names.arg = c("Strongly \n Disagree",
                      "Somewhat \n Disagree",
                      "Neither",
                      "Somewhat \n Agree",
                      "Somewhat \n Disagree"),
        col="black", las=1,
        cex.main=.8,
        cex.axis=.8, cex.names=.8, cex.lab=.8)
abline(h=seq(0, .4, .1), lty=2, col="light gray")
dev.off()

png("appfigs/sharedist.png", width = 6, height = 4, units="in", res=300)
barplot(prop.table(table(candlong$shares.ps)),
        ylim = c(0, .4),
        main = "Candidate shares my views",
        ylab= "Proportion of Respondents",
        names.arg = c("Strongly \n Disagree",
                      "Somewhat \n Disagree",
                      "Neither",
                      "Somewhat \n Agree",
                      "Somewhat \n Disagree"),
        col="black", las=1,
        cex.main=.8,
        cex.axis=.8, cex.names=.8, cex.lab=.8)
abline(h=seq(0, .4, .1), lty=2, col="light gray")
dev.off()



png("appfigs/caredist.png", width = 6, height = 4, units="in", res=300)
barplot(prop.table(table(candlong$cares.ps)),
        ylim = c(0, .4),
        main = "Candidate cares about people like me",
        ylab= "Proportion of Respondents",
        names.arg = c("Strongly \n Disagree",
                      "Somewhat \n Disagree",
                      "Neither",
                      "Somewhat \n Agree",
                      "Somewhat \n Disagree"),
        col="black", las=1,
        cex.main=.8,
        cex.axis=.8, cex.names=.8, cex.lab=.8)
abline(h=seq(0, .4, .1), lty=2, col="light gray")
dev.off()
```

![](appfigs/moraldist.png){width=40%}\
![](appfigs/sharedist.png){width=40%} ![](appfigs/caredist.png){width=40%}\
